#include "stdafx.h"
#include "TCPInputStream.h"

TCPInputStream::TCPInputStream(SOCKET socket): m_socket(socket)
{

}
TCPInputStream::TCPInputStream(const char *addr, int port)
{
	
}
TCPInputStream::~TCPInputStream()
{
	close();
}

int TCPInputStream::read(char buf[], int len)
{
	if(m_socket == INVALID_SOCKET)
		return -1;
	int ret = recv(m_socket, buf, len, 0);
	if(ret == 0 || ret == SOCKET_ERROR)
		return -1;
	else return ret;
}

void TCPInputStream::close()
{
	if(m_socket != INVALID_SOCKET)
	{
		closesocket(m_socket);
		m_socket = INVALID_SOCKET;
	}
}